-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Text rendering #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds end-to-end text rendering support by integrating a new WGSL shader, extending the JS reconciler, GUI layout, and GPU pipeline, and wiring it into the application loop.
- Introduces
text_shader.wgsl
for push-constant viewport handling and text sampling - Extends the JS reconciler and Deno ops with
create_text_node
andTextInstance
- Updates
Gui
,Gpu
, andApp
in Rust to support text node creation, layout, rendering, and DPI scaling
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/text_shader.wgsl | New WGSL vertex/fragment shader for textured text quads |
src/javascript_runtime/reconciler.ts | Added create_text_node op, TextInstance type, and reconciler handling |
src/javascript_runtime/mod.rs | Implemented op_create_text_node and registered the op |
src/gui.rs | Added NodeKind::Text , text node creation, layout and collection |
src/gpu.rs | Integrated TextRenderer , DPI scaling, and text draw/update methods |
src/app.rs | Hooked text collection and rendering into event handlers |
src/main.tsx | Display placeholder text instead of empty div |
src/main.rs | Registered new text module |
Cargo.toml | Added cosmic-text dependency for text rendering |
Comments suppressed due to low confidence (3)
src/gui.rs:140
- New text rendering logic isn't covered by unit or integration tests; consider adding tests for create_text_node and collect_text_instances to ensure text nodes behave as expected.
pub fn create_text_node(
src/javascript_runtime/reconciler.ts:26
- [nitpick] Using RectId for text nodes may be misleading since this ID now represents text instances. Consider renaming RectId to a more generic identifier like InstanceId or NodeId to accurately reflect its usage.
type TextInstance = { type: "text"; id: RectId };
src/gui.rs:160
- [nitpick] Using println! for debugging in production code can be noisy and isn't configurable by log level. Consider using a logging framework (e.g., the log crate) with appropriate log levels.
println!("create_text_node {:?} {:?} {:?}",
let text_items = gui.collect_text_instances(); | ||
println!("GuiUpdate: collected {} text items", text_items.len()); | ||
let mut all_text_instances = Vec::new(); | ||
|
||
for (text, x, y, font_size, color, max_width) in text_items { | ||
let text_instances = gpu.render_text(&text, x, y, font_size, color, Some(max_width)); | ||
all_text_instances.extend(text_instances); | ||
} | ||
|
||
println!("GuiUpdate: updating GPU with {} text instances", all_text_instances.len()); | ||
gpu.update_text_instances(&all_text_instances); |
Copilot
AI
Jun 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic to collect and update text instances is duplicated across GuiUpdate, Resized, and ScaleFactorChanged handlers. Consider extracting this into a helper method to reduce code duplication.
let text_items = gui.collect_text_instances(); | |
println!("GuiUpdate: collected {} text items", text_items.len()); | |
let mut all_text_instances = Vec::new(); | |
for (text, x, y, font_size, color, max_width) in text_items { | |
let text_instances = gpu.render_text(&text, x, y, font_size, color, Some(max_width)); | |
all_text_instances.extend(text_instances); | |
} | |
println!("GuiUpdate: updating GPU with {} text instances", all_text_instances.len()); | |
gpu.update_text_instances(&all_text_instances); | |
self.collect_and_render_text_instances(window, gpu, &mut gui); |
Copilot uses AI. Check for mistakes.
No description provided.